/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Ali Ok (www.aliok.info) - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.search;

import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.search.ui.ISearchPage;
import org.eclipse.search.ui.ISearchPageContainer;
import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

public class SearchPage extends DialogPage implements ISearchPage {

	private Text expressionText;
	private ISearchPageContainer container;

	public SearchPage() {
		super("CVS Search");
	}

	public SearchPage(String title) {
		super(title);
	}

	public SearchPage(String title, ImageDescriptor image) {
		super(title, image);
	}

	public boolean performAction() {
		NewSearchUI.runQueryInBackground(new SearchQuery(expressionText.getText(),container));
		return true;
	}

	public void setContainer(ISearchPageContainer container) {
		this.container = container;
	}

	public void createControl(Composite parent) {
		Composite root = new Composite(parent, SWT.NONE);
		root.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		root.setLayout(layout);
		Label expressionLabel = new Label(root, SWT.NONE);
		expressionLabel.setText("Expression");
		expressionText = new Text(root, SWT.BORDER);
		expressionText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING,
				true, true));
		setControl(root);
	}

}
